In [1]:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import plotly.graph_objects as go
import plotly.express as px
import datetime
from plotly.subplots import make_subplots
import requests
#from bs4 import BeautifulSoup
import seaborn as sns
In [2]:
data = pd.read_csv("D:/kaggle Data/novel-corona-virus-2019-dataset update till jun/covid_19_data.csv")
In [3]:
data.head()
Out[3]:
SNo ObservationDate Province/State Country/Region Last Update Confirmed Deaths Recovered
0 1 1/22/2020 Anhui Mainland China 1/22/2020 17:00 1 0 0
1 2 1/22/2020 Beijing Mainland China 1/22/2020 17:00 14 0 0
2 3 1/22/2020 Chongqing Mainland China 1/22/2020 17:00 6 0 0
3 4 1/22/2020 Fujian Mainland China 1/22/2020 17:00 1 0 0
4 5 1/22/2020 Gansu Mainland China 1/22/2020 17:00 0 0 0

Calculating the Percentage of missing values

In [4]:
# Percetage of NA Values

NA = [(c, data[c].isna().mean()*100) for c in data]
NA = pd.DataFrame(NA, columns=["Column_name","Percentage"])
NA
Out[4]:
Column_name Percentage
0 SNo 0.000000
1 ObservationDate 0.000000
2 Province/State 40.970995
3 Country/Region 0.000000
4 Last Update 0.000000
5 Confirmed 0.000000
6 Deaths 0.000000
7 Recovered 0.000000
In [5]:
data["Province/State"] = data["Province/State"].fillna('unknown')

Change Data type Confirmed, Deaths, Recoverd into int

In [6]:
data[["Confirmed", "Deaths", "Recovered"]] = data[["Confirmed", "Deaths", "Recovered"]].astype(int)

Replacing Mainland China to China

In [7]:
data["Country/Region"] = data["Country/Region"].replace("Mainland China", "China")
In [8]:
data["Current_case"] = data["Confirmed"]- data["Deaths"]-data["Deaths"]
data
Out[8]:
SNo ObservationDate Province/State Country/Region Last Update Confirmed Deaths Recovered Current_case
0 1 1/22/2020 Anhui China 1/22/2020 17:00 1 0 0 1
1 2 1/22/2020 Beijing China 1/22/2020 17:00 14 0 0 14
2 3 1/22/2020 Chongqing China 1/22/2020 17:00 6 0 0 6
3 4 1/22/2020 Fujian China 1/22/2020 17:00 1 0 0 1
4 5 1/22/2020 Gansu China 1/22/2020 17:00 0 0 0 0
... ... ... ... ... ... ... ... ... ...
48090 48091 6/22/2020 Zacatecas Mexico 6/23/2020 4:33 706 75 442 556
48091 48092 6/22/2020 Zakarpattia Oblast Ukraine 6/23/2020 4:33 2188 57 842 2074
48092 48093 6/22/2020 Zaporizhia Oblast Ukraine 6/23/2020 4:33 555 16 391 523
48093 48094 6/22/2020 Zhejiang China 6/23/2020 4:33 1269 1 1267 1267
48094 48095 6/22/2020 Zhytomyr Oblast Ukraine 6/23/2020 4:33 1270 23 633 1224

48095 rows × 9 columns

Get Last Update

In [9]:
Data = data[data["ObservationDate"] == max(data["ObservationDate"])].reset_index()

COVID-19 in the World Case

In [10]:
data_world = Data.groupby(["ObservationDate"])[["Confirmed", "Current_case","Recovered","Deaths"]].sum().reset_index()
In [11]:
labels = ["Last Update","Confirmed","Current_case","Recovered","Deaths"]
fig = go.Figure(data=[go.Table(header=dict(values=labels),
                              cells=dict(values=data_world.loc[0,["ObservationDate","Confirmed", 
                                                                  "Current_case","Recovered","Deaths"]]))])

fig.update_layout(
    title="Corona Virus in the World"
)
fig.show()

Pie Diagram

In [12]:
labels = ["Current_cases","Recovered","Deaths"]
values = data_world.loc[0, ["Current_case","Recovered","Deaths"]]
fig = px.pie(data_world, values=values, names=labels,color_discrete_sequence=['rgb(77,146,33)',
                                                                              'rgb(69,144,185)','rgb(77,77,77)'],hole=0.7)
fig.update_layout(
    title='Total cases : '+str(data_world["Confirmed"][0]),
)
fig.show()

Evalution of Corona Virus Over Time

In [13]:
data_over_time= data.groupby(["ObservationDate"])[["Confirmed","Current_case","Recovered",
                                                   "Deaths"]].sum().reset_index().sort_values("ObservationDate", 
                                                    ascending =True).reset_index(drop=True)
In [14]:
fig = go.Figure()
fig.add_trace(go.Scatter(x=data_over_time.index, y=data_over_time["Confirmed"],
                        mode = 'lines',
                         name = "Confirmed Cases"
                        ))

fig.update_layout(
    title = "Evalution of Confirm Case Over Time in the world", 
    template = 'plotly_white',
    yaxis_title="Confirmed cases",
    xaxis_title="Days",
)

fig.show()
In [15]:
fig = go.Figure()
fig.add_trace(go.Scatter(x=data_over_time.index, y=data_over_time['Current_case'],
                    mode='lines', marker_color="black",
                    name='Current_cases', line=dict(dash="dot")))


fig.update_layout(
    title='Evolution of Current cases over time in the world',
        template='plotly_white',
    yaxis_title = 'Current cases',
    xaxis_title = 'Days',

)

fig.show()
In [16]:
fig = go.Figure()
fig.add_trace(go.Scatter(x=data_over_time.index, y=data_over_time['Recovered'],
                    mode='lines', 
                    name='Recovered', marker_color="green",))


fig.update_layout(
    title='Evolution of Recovered cases over time in the world',
        template='plotly_white',
    yaxis_title = 'Recovered cases',
    xaxis_title = 'Days',

)

fig.show()
In [17]:
fig = go.Figure()
fig.add_trace(go.Scatter(x=data_over_time.index, y=data_over_time['Deaths'],
                    mode='lines', marker_color="red",
                    name='Deaths', line=dict(dash="dot")))


fig.update_layout(
    title='Evolution of Death cases over time in the world',
        template='plotly_white',
    yaxis_title="Death cases",
    xaxis_title="Days",

)

fig.show()
In [18]:
fig = go.Figure(go.Bar(
    x = data_over_time["ObservationDate"],
    y = data_over_time["Confirmed"],
))

fig.update_layout(
    title = "Confirmed Cases in every day",
    template = "plotly_dark",
    xaxis_title = "Confirmed Cases",
    yaxis_title = "Days",
)

fig.show()
In [19]:
fig = go.Figure(go.Bar(
    x = data_over_time["ObservationDate"],
    y = data_over_time["Current_case"],
    marker_color = "rgb(253,187,132)"
))

fig.update_layout(
    title = "Current Cases in every day",
    template = "plotly_dark",
    xaxis_title = "Current Cases",
    yaxis_title = "Days",
)

fig.show()
In [20]:
fig = go.Figure(go.Bar(
    x = data_over_time["ObservationDate"],
    y = data_over_time["Recovered"],
    marker_color = "rgb(178,24,42)"
))

fig.update_layout(
    title = "Confirmed Cases in every day",
    template = "plotly_dark",
    xaxis_title = "Recovered Cases",
    yaxis_title = "Days",
)

fig.show()
In [21]:
fig = go.Figure(go.Bar(
    x = data_over_time["ObservationDate"],
    y = data_over_time["Deaths"],
    marker_color = "rgb(14,48,101)"   
))

fig.update_layout(
    title = "Death cases in every day",
    template = "plotly_dark",
    xaxis_title = "Death Case",
    yaxis_title = "Days",
)

fig.show()

Confirmed cases in each country

In [22]:
data_country = data.groupby(["Country/Region"])["Confirmed","Current_case","Recovered",
                                                "Deaths"].sum().reset_index().sort_values("Confirmed", 
                                                              ascending=False).reset_index(drop=True)
c:\users\hp\appdata\local\programs\python\python37-32\lib\site-packages\ipykernel_launcher.py:1: FutureWarning:

Indexing with multiple keys (implicitly converted to a tuple of keys) will be deprecated, use a list instead.

In [23]:
headerColor = 'grey'
rowEvenColor = 'lightgrey'
rowOddColor = 'white'

fig = go.Figure(data=[go.Table(
  header=dict(
    values=['<b>Country</b>','<b>Confirmed Cases</b>'],
    line_color='darkslategray',
    fill_color=headerColor,
    align=['left','center'],
      
    font=dict(color='white', size=12)
  ),
  cells=dict(
    values=[
      data_country['Country/Region'],
      data_country['Confirmed'],
      ],
    line_color='darkslategray',
    
    fill_color = [[rowOddColor,rowEvenColor,rowOddColor, rowEvenColor,rowOddColor]*len(data_country)],
    align = ['left', 'center'],
    font = dict(color = 'darkslategray', size = 11)
    ))
])
fig.update_layout(
    title='Confirmed Cases In Each Country',
)
fig.show()
In [24]:
fig = go.Figure(go.Bar(
    x = data_country["Confirmed"],
    y = data_country["Country/Region"],
    orientation="h"
))

fig.update_layout(
    title = "Confirmed Cases in Each Country",
    template = "plotly_dark",
    xaxis_title="Confirmed Cases",
    yaxis_title = "Countries",
)

fig.show()
In [25]:
fig = go.Figure(go.Bar(
    x = data_country["Recovered"],
    y = data_country["Country/Region"],
    orientation="h",
    marker_color = "#2CA02D",
))

fig.update_layout(
    title = "Recovered Cases in Each Country",
    template = "plotly_dark",
    xaxis_title="Recovered Cases",
    yaxis_title = "Countries",
)

fig.show()
In [26]:
fig = go.Figure(go.Bar(
    x = data_country["Deaths"],
    y = data_country["Country/Region"],
    orientation="h",
    marker_color = "#DC3956",
))

fig.update_layout(
    title = "Deaths Cases in Each Country",
    template = "plotly_dark",
    xaxis_title="Deaths Cases",
    yaxis_title = "Countries",
)

fig.show()
In [27]:
data_per_country = data.groupby(["Country/Region","ObservationDate"])[["Confirmed","Current_case",
                            "Recovered","Deaths"]].sum().reset_index().sort_values("ObservationDate",
                            ascending=True).reset_index(drop=True)
In [28]:
fig = px.choropleth(data_per_country, locations=data_per_country['Country/Region'],
                    color=data_per_country['Confirmed'],locationmode='country names', 
                    hover_name=data_per_country['Country/Region'], 
                    color_continuous_scale=px.colors.sequential.deep,
                    animation_frame="ObservationDate")
fig.update_layout(

    title='Evolution of confirmed cases In Each Country',
)
fig.show()

Top 10 Infected Countries

In [29]:
fig = go.Figure(data=[go.Bar(
            x=data_country['Country/Region'][0:10],
            y=data_country['Confirmed'][0:10],
            text=data_per_country['Confirmed'][0:10],
#             textposition='auto',
            marker_color='white',
            

        )])
fig.update_layout(
    title='Top 10  infected Countries',
    xaxis_title="Countries",
    yaxis_title="Confirmed Cases",
        template='plotly_dark'

)
fig.show()
In [30]:
fig = go.Figure(data=[go.Scatter(
    x=data_country['Country/Region'][0:10],
    y=data_country['Confirmed'][0:10],
    mode='markers',
    
    marker=dict(
        color=100+np.random.randn(500),
        size=(data_country['Confirmed'][0:10]/1000000),
        showscale=True
        )
)])

fig.update_layout(
    title='Most 10 infected Countries',
    xaxis_title="Countries",
    yaxis_title="Confirmed Cases",
    template='plotly_dark'
)
fig.show()

Recoverd cases in each country

In [31]:
recovered_country = data.groupby(["Country/Region"])["Recovered"].sum().reset_index().sort_values("Recovered",
                                ascending=False).reset_index(drop=True)
In [32]:
headerColor = 'grey'
rowEvenColor = 'lightgrey'
rowOddColor = 'white'

fig = go.Figure(data=[go.Table(
  header=dict(
    values=['<b>Country</b>','<b>Recovered Cases</b>'],
    line_color='darkslategray',
    fill_color=headerColor,
    align=['left','center'],
      
    font=dict(color='white', size=12)
  ),
  cells=dict(
    values=[
      data_country['Country/Region'],
      data_country['Recovered'],
      ],
    line_color='darkslategray',
    
    fill_color = [[rowOddColor,rowEvenColor,rowOddColor, rowEvenColor,rowOddColor]*len(data_country)],
    align = ['left', 'center'],
    font = dict(color = 'darkslategray', size = 11)
    ))
])
fig.update_layout(
    title='Recovered Cases In Each Country',
)
fig.show()
In [33]:
fig = px.pie(recovered_country, values = recovered_country['Recovered'],
            names=recovered_country["Country/Region"],
            title = "Recovered Cases",
            )

fig.update_traces(textposition = "inside",
                textinfo = "percent+label")

fig.update_layout(template = "plotly_dark")
fig.show()
In [34]:
fig = go.Figure(data=[go.Bar(
        x= recovered_country["Country/Region"][0:10],
        y= recovered_country["Recovered"][0:10],
        textposition = "auto",
        marker_color = "lightgreen",
)])

fig.update_layout(
    title = "Top 10 Infected Country",
    xaxis_title = "Countries",
    yaxis_title = "Recovered Cases",
    template= "plotly_dark"
)

fig.show()

Deaths cases in each country

In [ ]:
 
In [35]:
headerColor = 'grey'
rowEvenColor = 'lightgrey'
rowOddColor = 'white'

fig = go.Figure(data=[go.Table(
  header=dict(
    values=['<b>Country</b>','<b>Deaths </b>'],
    line_color='darkslategray',
    fill_color=headerColor,
    align=['left','center'],
      
    font=dict(color='white', size=12)
  ),
  cells=dict(
    values=[
      data_country['Country/Region'],
      data_country["Deaths"],
      ],
    line_color='darkslategray',
    
    fill_color = [[rowOddColor,rowEvenColor,rowOddColor, rowEvenColor,rowOddColor]*len(data_country)],
    align = ['left', 'center'],
    font = dict(color = 'darkslategray', size = 11)
    ))
])
fig.update_layout(
    title='Deaths Cases In Each Country',
)
fig.show()
In [ ]:
fig = go.Figure(data=[go.Bar(
        x= recovered_country["Country/Region"][0:10],
        y= recovered_country["Deaths"][0:10],
        textposition = "auto",
        marker_color = "red",
)])

fig.update_layout(
    title = "Top 10 Infected Country",
    xaxis_title = "Countries",
    yaxis_title = "Dea Cases",
    template= "plotly_dark"
)

fig.show()

Corona Virus in my India

In [36]:
data_india = data[(data["Country/Region"] == "India")].reset_index(drop=True)
data_india
Out[36]:
SNo ObservationDate Province/State Country/Region Last Update Confirmed Deaths Recovered Current_case
0 431 1/30/2020 unknown India 1/30/2020 16:00 1 0 0 1
1 492 1/31/2020 unknown India 1/31/2020 23:59 1 0 0 1
2 548 2/1/2020 unknown India 1/31/2020 8:15 1 0 0 1
3 608 2/2/2020 unknown India 2020-02-02T06:03:08 2 0 0 2
4 673 2/3/2020 unknown India 2020-02-03T21:43:02 3 0 0 3
... ... ... ... ... ... ... ... ... ...
595 48028 6/22/2020 Tripura India 6/23/2020 4:33 1237 1 782 1235
596 48042 6/22/2020 Unknown India 6/23/2020 4:33 8015 0 0 8015
597 48049 6/22/2020 Uttar Pradesh India 6/23/2020 4:33 18322 569 11601 17184
598 48050 6/22/2020 Uttarakhand India 6/23/2020 4:33 2402 28 1521 2346
599 48076 6/22/2020 West Bengal India 6/23/2020 4:33 14358 569 8687 13220

600 rows × 9 columns

In [37]:
fig = go.Figure()
fig.add_trace(go.Scatter(
    x = data_india["ObservationDate"],
    y = data_india["Confirmed"],
    mode = "lines",
    name = "Confirmed Cases"
))

fig.add_trace(go.Scatter(
    x = data_india["ObservationDate"],
    y = data_india["Current_case"],
    mode = "lines",
    name = "Confirmed Cases", line = dict(dash="dot")
))

fig.add_trace(go.Scatter(
    x = data_india["ObservationDate"],
    y = data_india["Recovered"],
    mode = "lines",
    name = "Recovered Cases", marker_color="green"
))

fig.add_trace(go.Scatter(
    x = data_india["ObservationDate"],
    y = data_india["Deaths"],
    mode = "lines",
    name = "Death Cases", line = dict(dash="dot"), marker_color= "black"
))

fig.update_layout(
    title = "Evalution cases over time in India",
    template = "plotly_white"
)

fig.show()
In [38]:
fig = go.Figure(go.Bar(
            x=data_india['ObservationDate'],
            y=data_india['Confirmed'],
    marker_color='rgb(13,48,100)'
           ))
fig.update_layout(
    title='Confirmed cases In Each Day',
    template='plotly_dark',
     xaxis_title="Confirmed cases",
    yaxis_title="Days",
)
fig.show()
In [39]:
fig = go.Figure(go.Bar(
            x=data_india['ObservationDate'],
            y=data_india['Current_case'],
    marker_color='rgb(13,48,70)'
           ))
fig.update_layout(
    title='Current cases In Each Day',
    template='plotly_dark',
     xaxis_title="Current cases",
    yaxis_title="Days",
)
fig.show()
In [40]:
fig = go.Figure(go.Bar(
            x=data_india['ObservationDate'],
            y=data_india['Recovered'],
    marker_color='rgb(11,48,100)'
           ))
fig.update_layout(
    title='Recovered cases In Each Day',
    template='plotly_dark',
     xaxis_title="Recovered cases",
    yaxis_title="Days",
)
fig.show()
In [41]:
fig = go.Figure(go.Bar(
            x=data_india['ObservationDate'],
            y=data_india['Deaths'],
    marker_color='rgb(13,48,100)'
           ))
fig.update_layout(
    title='Deaths cases In Each Day',
    template='plotly_dark',
     xaxis_title="Deaths cases",
    yaxis_title="Days",
)
fig.show()
In [42]:
data_india_latest=data_india[data_india["ObservationDate"] == max(data_india["ObservationDate"])].reset_index()

data_india_latest
Out[42]:
index SNo ObservationDate Province/State Country/Region Last Update Confirmed Deaths Recovered Current_case
0 131 38010 6/9/2020 unknown India 6/10/2020 4:07 276146 7750 134670 260646
In [43]:
data_india_state = data_india_latest.groupby(["Province/State"])["Confirmed","Current_case","Recovered","Deaths"].sum().reset_index().sort_values("Confirmed", ascending=False).reset_index(drop=True)
c:\users\hp\appdata\local\programs\python\python37-32\lib\site-packages\ipykernel_launcher.py:1: FutureWarning:

Indexing with multiple keys (implicitly converted to a tuple of keys) will be deprecated, use a list instead.

In [44]:
fig = px.pie(data_india_state, values= data_india_state["Confirmed"],
             names=data_india_state["Province/State"],
            title="Confirmed Cases in India", hole=.2)
fig.update_traces(
    textposition="inside", textinfo = "percent+label"
)

fig.show()